package com.crm.controller;

import com.crm.DTO.TransferDto;
import com.crm.common.result.AjaxResult;
import com.crm.common.result.TableDataInfo;
import com.crm.service.BusinessService;
import com.crm.service.ClueService;
import com.crm.service.system.ISysUserService;
import com.crm.vo.TransferVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/transfer")
@RestController
public class TransferController {

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private BusinessService businessService;
    @Autowired
    private ClueService clueService;

    /**
     * 待转移列表
     *
     * @param transferDto
     * @return
     */
    @RequestMapping("/list")
    public TableDataInfo<TransferVo> list(TransferDto transferDto) {
        List<TransferVo> list = sysUserService.transferList(transferDto);
        return TableDataInfo.success(list);
    }

    /**
     * 分配
     *
     * @param type       0:线索 1:商机
     * @param ownerId    现在的负责人ID
     * @param transferId 要分配的用户ID
     * @return
     */
    @RequestMapping("/assignment/{type}/{ownerId}/{transferId}")
    public AjaxResult assignment(@PathVariable Integer type, @PathVariable Long ownerId, @PathVariable Long transferId) {
        // 线索
        if (type == 0) {
            clueService.assignment(ownerId, transferId);
        }
        // 商机
        else if (type == 1) {
            businessService.assignment(ownerId, transferId);
        }

        return AjaxResult.success("分配成功");
    }

}
